package fun.lifepoem.blog.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @author Yiwyn
 * @create 2022/10/26 20:15
 */
@Service
public class RedisService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void setKey(String key, Object data) {
        redisTemplate.opsForValue().set(key, data);
    }

    public void setKey(String key, Object data, long delyTime,TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, data, delyTime, timeUnit);
    }

    public void deleteKey(String... key) {
        redisTemplate.delete(Arrays.asList(key));
    }


    public Object getKey(String key) {
        Object data = redisTemplate.opsForValue().get(key);
        return data;
    }


}
